package com.example.st.controller;

import com.example.st.common.ResponseResult;
import com.example.st.entity.Bp;
import com.example.st.service.BpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bps")
public class BpController {

    @Autowired
    private BpService bpService;

    @GetMapping
    public ResponseResult getAllBps() {
        ResponseResult<List<Bp>> response = bpService.getAllBps();
        return response;
    }

    @GetMapping("/{pid}")
    public ResponseResult getBpById(@PathVariable("pid") Long pid) {
        ResponseResult<Bp> response = bpService.getBpById(pid);
        return response;
    }

    @GetMapping("/uid/{uid}")
    public ResponseResult getBpByUid(@PathVariable("uid") Long uid) {
        ResponseResult<List<Bp>> response = bpService.getBpByUid(uid);
        return response;
    }

    @PostMapping
    public ResponseResult createBp(@RequestBody Bp bp) {
        ResponseResult<Bp> response = bpService.createBp(bp);
        return response;
    }

    @PutMapping("/{pid}")
    public ResponseResult updateBp(@PathVariable("pid") Long pid, @RequestBody Bp bpDetails) {
        ResponseResult<Bp> response = bpService.updateBp(pid, bpDetails);
        return response;
    }

    @DeleteMapping("/{pid}")
    public ResponseResult deleteBp(@PathVariable("pid") Long pid) {
        ResponseResult<Void> response = bpService.deleteBp(pid);
        return response;
    }
}

